<?php
namespace app\admin\controller;

use app\admin\model\Member as User;
use app\admin\model\Order;
class Index extends Base
{
    public function index()
    {
        return view('index/index');
    }
    public function welcome()
    {

        $user_count = User::count();//用户总数
        $user_count_today = User::where('create_time','>=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y'))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1))->count();//今日新增用户
        $user_count_yestoday = User::where('create_time','>=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-1,date('Y'))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y'))-1))->count();//昨日新增用户

        $user_count_week = User::where('create_time','>=',date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))))->count();//本周新增用户

        $user_count_month = User::where('create_time','>=',date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))))->count();//本月新增用户



        $order_count = Order::count();//订单总数
        $order_count_today = Order::where('create_time','>=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y'))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1))->count();//今日新增订单
        $order_count_yestoday = Order::where('create_time','>=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-1,date('Y'))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y'))-1))->count();//昨日新增订单

        $order_count_week = Order::where('create_time','>=',date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))))->count();//本周新增订单

        $order_count_month = Order::where('create_time','>=',date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))))
            ->where('create_time','<=',date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))))->count();//本月新增订单


        return view('index/welcome',[
            'user_count'=>$user_count,
            'user_count_today'=>$user_count_today,
            'user_count_yestoday'=>$user_count_yestoday,
            'user_count_week'=>$user_count_week,
            'user_count_month'=>$user_count_month,
            'order_count'=>$order_count,
            'order_count_today'=>$order_count_today,
            'order_count_yestoday'=>$order_count_yestoday,
            'order_count_week'=>$order_count_week,
            'order_count_month'=>$order_count_month
        ]);
    }

}
